const User = require("../database/models/user");


async function checkUser(req, res, next) {
  let account = req.body.account;
  let password = req.body.password;
  // checkUser函数的req参数接收传来的数据，
  const data = await User.findAll({
    where: {
      account: account
    }
  });
  if (data[0]) {
    if (data[0].dataValues.account !== account || data[0].dataValues.password !== password) {
      return res.status(400).send({
        Informationerror: "账号或密码错误！！"
      });
    };
  };
  // status(404)不存在该数据
  if (!data[0]) return res.status(404).send({ Informationerror: "该账号不存在！" })

  return next();
}

// 导出该中间件
module.exports = checkUser;
